package com.zero.mxshengadmin.modules.website.controller;

import com.zero.mxshengadmin.common.utils.PageUtils;
import com.zero.mxshengadmin.common.utils.R;
import com.zero.mxshengadmin.modules.website.entity.WebsiteAdvertiseEntity;
import com.zero.mxshengadmin.modules.website.entity.WebsiteNewsEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by aicaikeji on 2019/4/3.
 */

@RestController
public class WebsiteNewsController {
    @Autowired
    private WebsiteNewsService websiteNewsService;
    /**
     * 添加资讯
     * @param entity
     * @return
     */
    @PostMapping("/website/news/add")
    public R save(@RequestBody WebsiteNewsEntity entity) {
        websiteNewsService.save(entity);
        return R.ok();
    }

    /**
     * 删除资讯
     * @param ids
     * @return
     */
    @PostMapping("/website/news/delete")
    public R delete(@RequestBody Long[] ids) {
        websiteNewsService.removeByIds(ids);
        return R.ok();
    }

    /**
     * 更新资讯
     * @param entity
     * @return
     */
    @PostMapping("/website/news/update")
    public R update(@RequestBody WebsiteNewsEntity entity) {
        websiteNewsService.update(entity);
        return R.ok();
    }

    /**
     * 查询某条资讯
     * @param id
     * @return
     */
    @GetMapping("/website/news/find/{id}")
    public R find(@PathVariable("id") Long id) {
        WebsiteNewsEntity entity = websiteNewsService.getById(id);
        return R.ok().put("result",entity);
    }

    /**
     * 查询资讯列表
     * @param params
     * @return
     */
    @GetMapping("/website/news/list")
    public R findList(@RequestParam Map<String, Object> params) {
        PageUtils page = websiteNewsService.queryPage(params);
        return R.ok().put("result",page);
    }
}
